package com.ghost.view.UI
{
	import com.adobe.cairngorm.control.CairngormEventDispatcher;
	import com.ghost.UI.Ghost_Btn;
	import com.ghost.data_struct.HashMap;
	import com.ghost.interfaces.Ibaseui;
	import com.ghost.interfaces.Ipop_win;
	import com.ghost.manager.Tip_manager;
	import com.ghost.model.Global_data;
	import com.ghost.model.Object_pool;
	import com.ghost.view.Base_effect;
	import com.ghost.view.pop.email.Email_pop;
	import com.ghost.view.pop.mall.Mall;
	import com.ghost.view.pop.pack.Pack;
	import com.ghost.view.pop.task.Task;
	
	import flash.display.Bitmap;
	import flash.events.MouseEvent;

	/**
	 * 菜单容器
	 * @author ghost
	 */	
	public class UI_menu_main extends Base_effect implements Ibaseui
	{
		private var ghost_btn:Ghost_Btn;
		private var btn_skin_v:Vector.<Object>;
		private var btn_name_arr:Vector.<String>;
		private var btn_register_class_v:Vector.<Object>;
		private var btn_register_class_hashmap:HashMap;
		public function UI_menu_main()
		{
			this.alpha=1;
			var bg_bp:Bitmap = new Bitmap(Object_pool.loaded_obj_pool.get("bottom_menu_ui").get("bottom_menu_bg"));
			this.addChild(bg_bp);
			btn_name_arr = new <String>["role","pack","task","mall"];
			btn_register_class_v = new <Object>[Email_pop,Pack,Task,Mall];
			btn_register_class_hashmap = new HashMap();
			btn_skin_v = new Vector.<Object>();
			btn_skin_v.push(new Bitmap(Object_pool.loaded_obj_pool.get("bottom_menu_ui").get("bottom_role_over")),new Bitmap(Object_pool.loaded_obj_pool.get("bottom_menu_ui").get("bottom_role_out")),
				new Bitmap(Object_pool.loaded_obj_pool.get("bottom_menu_ui").get("bottom_pack_over")),new Bitmap(Object_pool.loaded_obj_pool.get("bottom_menu_ui").get("bottom_pack_out")),
				new Bitmap(Object_pool.loaded_obj_pool.get("bottom_menu_ui").get("bottom_task_over")),new Bitmap(Object_pool.loaded_obj_pool.get("bottom_menu_ui").get("bottom_task_out")),
				new Bitmap(Object_pool.loaded_obj_pool.get("bottom_menu_ui").get("bottom_mall_over")),new Bitmap(Object_pool.loaded_obj_pool.get("bottom_menu_ui").get("bottom_mall_out")));
			var i:int = 0;
			for(;i<btn_name_arr.length;i++)
			{
				ghost_btn = new Ghost_Btn(new <Object>[btn_skin_v[i*2],btn_skin_v[(i+1)*2-1],btn_skin_v[(i+1)*2-1],btn_skin_v[(i+1)*2-1]],call_back);
				ghost_btn.setsize(56,54);
				ghost_btn.name = btn_name_arr[i];
				this.addChild(ghost_btn);
				btn_register_class_hashmap.put(btn_name_arr[i],btn_register_class_v[i]);
				ghost_btn.x = i*(ghost_btn.width+5);
				Tip_manager.getInstance().add_tip(ghost_btn,btn_name_arr[i]);
			}
			bg_bp.y = ghost_btn.height-bg_bp.height;
		}
		public function hide():void
		{
			this.visible = false;
		}
		public function show():void
		{
			this.visible = true;
		}
		private var consult_h:Number=0;
		public function reflash_x_y(e:*):void
		{
			this.x = Global_data.stage_s_width-this.width;
			if(this.parent.getChildByName("bottom_exp"))consult_h=this.parent.getChildByName("bottom_exp").height;
			this.y = Global_data.stage_s_height-this.height-consult_h;
		}
		private function call_back(e:MouseEvent):void
		{
			creat(e.target.name);
		}
		private var exist_name_v:Vector.<String>=new Vector.<String>;//已经存在的pop名字
		private var exist_pop_hashmap:HashMap=new HashMap();//已经存在的pop
		private var cl:Class;//获得相应的类
		private var pop:Ipop_win;//获得相应的pop
		private function creat(str:String):void
		{
			if(exist_name_v.indexOf(str)==-1)
			{
				exist_name_v.push(str);
				cl = btn_register_class_hashmap.get(str);
				pop = new cl() as Ipop_win;
				exist_pop_hashmap.put(str,pop);
			}
			else
			{
				pop = exist_pop_hashmap.get(str);
			}
			pop.creat_win();
		}
		/**
		 * 处理键盘事件 
		 * @param str调用的模块name
		 */		
		public function key_init(str:String):void
		{
			creat(str);
		}
	}
}